#!/usr/bin/env python
# encoding=utf-8

import sys
import json
import datetime

import tornado.ioloop
import tornado.web
from concurrent.futures import ThreadPoolExecutor
from scpy.logger import get_logger
from tornado.concurrent import run_on_executor

logger = get_logger(__file__)

reload(sys)
sys.setdefaultencoding('utf-8')


class FileHandler(tornado.web.RequestHandler):
    executor = ThreadPoolExecutor(max_workers=config.WORKERS)

    @run_on_executor
    def get(self):
        self.set_header('Content-Type', 'application/json;charset="utf-8"')
        self.write({'code': 200})

if __name__ == '__main__':
    SERVER_PORT = 7200
    application = tornado.web.Application(
        [
            (r'/api/insertTask', FileHandler),
        ], debug=False)
    application.listen(SERVER_PORT, address='0.0.0.0')
    logger.info('tornado server started on port %s', SERVER_PORT)
    tornado.ioloop.IOLoop.instance().start()
